//
//  UserCenterViewController.m
//  FingerUniversity
//
//  Created by vantle on 16/3/11.
//  Copyright © 2016年 vantle. All rights reserved.
//

#import "UserCenterViewController.h"
#import "UpdatePassWordViewController.h"
#import "SVProgressHUD.h"
#import "AFNetworking.h"
#import "loginViewController.h"
#import "MobClick.h"
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
@interface UserCenterViewController ()

@end

@implementation UserCenterViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [MobClick beginLogPageView:@"UserCenterViewController"];//("PageOne"为页面名称，可自定义)
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"UserCenterViewController"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    UIImageView*bg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
    bg.image=[UIImage imageNamed:@"bg"];
    [self.view addSubview:bg];
    
    UIImageView*barImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth, 44)];
    barImage.userInteractionEnabled=YES;
    barImage.backgroundColor=[UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1];
    [self.view addSubview:barImage];
    
    UIButton*backButton=[UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame=CGRectMake(0, 0, 100, 44);
    [backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [barImage addSubview:backButton];
    
    UIImageView*backImage=[[UIImageView alloc]initWithFrame:CGRectMake(5, 12, 5, 20)];
    backImage.image=[UIImage imageNamed:@"back_arrowleft"];
    [barImage addSubview:backImage];
    
    UIImageView*logoImage=[[UIImageView alloc]initWithFrame:CGRectMake(backImage.frame.origin.x+backImage.frame.size.width+3, 6, 32, 32)];
    logoImage.layer.cornerRadius=3;
    logoImage.clipsToBounds=YES;
    logoImage.image=[UIImage imageNamed:@"app-logo-80"];
    [barImage addSubview:logoImage];
    
    UILabel*noticeLabel=[[UILabel alloc]initWithFrame:CGRectMake(logoImage.frame.origin.x+logoImage.frame.size.width+5, 10, 100, 25)];
    noticeLabel.text=@"用户中心";
    [barImage addSubview:noticeLabel];
    
    
    _tabelView=[[UITableView alloc]initWithFrame:CGRectMake(5, 64+10, ScreenWidth-10, 180)];
    _tabelView.dataSource=self;
    _tabelView.delegate=self;
    _tabelView.rowHeight=60;
    _tabelView.separatorColor=[UIColor whiteColor];
    _tabelView.backgroundColor=[UIColor clearColor];
    _tabelView.bounces=NO;
    [self.view addSubview:_tabelView];
    
    UIButton*cancelButton=[UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.frame=CGRectMake(5, _tabelView.frame.origin.y+_tabelView.frame.size.height+15, ScreenWidth-10, 40);
    [cancelButton setBackgroundImage:[UIImage imageNamed:@"圆角矩形-1"] forState:UIControlStateNormal];
    [cancelButton setTitle:@"注销" forState:UIControlStateNormal];
    [cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self .view addSubview:cancelButton];
    
    
    _titleArray=@[@"密码修改",@"消息提醒",@"清空搜索记录"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString*cellIndentifier=@"cell";
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
        UIImageView*rightArrow=[[UIImageView alloc]init];
        rightArrow.center=CGPointMake(ScreenWidth-30, cell.contentView.center.y+10);
        rightArrow.bounds=CGRectMake(0, 0, 15, 20);
        rightArrow.image=[UIImage imageNamed:@"jiantou"];
        [cell.contentView addSubview:rightArrow];
        
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.textLabel.text=_titleArray[indexPath.row];
    cell.textLabel.font=[UIFont systemFontOfSize:19];
    cell.backgroundColor=[UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:0.5];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        UpdatePassWordViewController*updateVC=[[UpdatePassWordViewController alloc]init];
        [self.navigationController pushViewController:updateVC animated:YES];
    }
    else if (indexPath.row==1)
    {
        [SVProgressHUD showImage:nil status:@"开发中，敬请期待～"];
    }
    else
    {
        [SVProgressHUD show];
        [self performSelector:@selector(end) withObject:self afterDelay:1];
    }
}
-(void)end
{
    [SVProgressHUD dismiss];
    [SVProgressHUD showImage:nil status:@"纪录已经清空"];
}
-(void)cancelButtonClick
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@"" forKey:@"loginName"];
    [userDefaults setObject:@"" forKey:@"passWord"];
    
    loginViewController*loginVC=[[loginViewController alloc]init];
    [self.navigationController pushViewController:loginVC animated:YES];
    //统计关闭
    [MobClick profileSignOff];
}
-(void)viewDidLayoutSubviews
{
    if ([_tabelView respondsToSelector:@selector(setSeparatorInset:)]) {
        [_tabelView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([_tabelView respondsToSelector:@selector(setLayoutMargins:)]) {
        [_tabelView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
-(void)backButtonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
